package com.grandbroad.eim.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.west.westclient.api.base.bean.LiveRoomDTOBean;
import com.easy.west.westclient.api.login.bean.User;
import com.grandbroad.eim.R;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FollowedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<LiveRoomDTOBean> userList = new ArrayList<>();

    public void setUserList(List<LiveRoomDTOBean> userList) {
        this.userList = userList;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.follow_item, viewGroup, false);
        return new FollowedViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        if (viewHolder instanceof FollowedViewHolder)
        {
            LiveRoomDTOBean user = userList.get(i);
            FollowedViewHolder followedViewHolder = (FollowedViewHolder) viewHolder;
            followedViewHolder.tvFollowUsername.setText(user.getUser().getName());
            followedViewHolder.tvFollowCount.setText("粉丝:0");
            if (!TextUtils.isEmpty(user.getUser().getAvatar()))
            {
                x.image().bind(followedViewHolder.imgUserFollowAvator,user.getUser().getAvatar());
            }
            else
            {
                followedViewHolder.imgUserFollowAvator.setBackgroundResource(R.drawable.icon_my_head_default);
            }

        }
    }

    @Override
    public int getItemCount()
    {
        return userList.size();
    }

    /**
     * 关注item
     */
    class FollowedViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_user_follow_avator)
        ImageView imgUserFollowAvator;
        @BindView(R.id.tv_follow_username)
        TextView tvFollowUsername;
        @BindView(R.id.tv_follow_count)
        TextView tvFollowCount;
        @BindView(R.id.tv_cancel_follow)
        TextView tvCancelFollow;
        public FollowedViewHolder(@NonNull View itemView)
        {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
